package com.lanou3g.Code0523;


import com.sun.deploy.net.HttpRequest;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/5/23;
 * Otherwise, I don't know who created it either
 */

public class FirstFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 初始化方法,作用等同于 servlet的init方法

    }

    @Override
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        // 每次执行过滤的时候 调用的方法
        // 放行这次请求
        System.out.println("first");
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf8");

        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        // 当filter销毁的时候,会调用的方法
    }
}
